package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.Message;
import java.util.List;

public class MessageSendListAdapter extends ArrayAdapter<Message> {

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2015-07-14 16:54:02 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final LinearLayout rootView;
    public final TextView tvLvSuccessReceivepeople;
    public final TextView tvLvSuccessSendtime;
    public final TextView tvLvSuccessContent;

    private ViewHolder(LinearLayout rootView, TextView tvLvSuccessReceivepeople,
        TextView tvLvSuccessSendtime, TextView tvLvSuccessContent) {
      this.rootView = rootView;
      this.tvLvSuccessReceivepeople = tvLvSuccessReceivepeople;
      this.tvLvSuccessSendtime = tvLvSuccessSendtime;
      this.tvLvSuccessContent = tvLvSuccessContent;
    }

    public static ViewHolder create(LinearLayout rootView) {
      TextView tvLvSuccessReceivepeople =
          (TextView) rootView.findViewById(R.id.tv_lv_success_receivepeople);
      TextView tvLvSuccessSendtime = (TextView) rootView.findViewById(R.id.tv_lv_success_sendtime);
      TextView tvLvSuccessContent = (TextView) rootView.findViewById(R.id.tv_lv_success_content);
      return new ViewHolder(rootView, tvLvSuccessReceivepeople, tvLvSuccessSendtime,
          tvLvSuccessContent);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_message_send, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    Message item = getItem(position);
    vh.tvLvSuccessReceivepeople.setText(
        mContext.getString(R.string.receivepeople, item.getReceiverName()));
    vh.tvLvSuccessSendtime.setText(mContext.getString(R.string.sendtime, item.getSendTime()));
    vh.tvLvSuccessContent.setText(mContext.getString(R.string.messageContent, item.getContent()));

    return vh.rootView;
  }

  private LayoutInflater mInflater;
  private Context mContext;

  // Constructors
  public MessageSendListAdapter(Context context, List<Message> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
    this.mContext = context;
  }

  public MessageSendListAdapter(Context context, Message[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
    this.mContext = context;
  }
}
